using Kassandra.Core;
using Kassandra.Core.Repositories;
using NUnit.Framework;
using Rhino.Mocks;

namespace Kassandra.Tests
{

    public class ImageRepositoryTests
    {
        [TestFixture]
        public class When_saving_an_image
        {
            private MockRepository _mockery;
            private ICharacterToFileNameTranslator _characterToFileNameTranslator;
            private IImageRepository _imageRepository;
            private IPersistFile _persistFile;

            [SetUp]
            public void Setup()
            {
                _mockery = new MockRepository();
                _characterToFileNameTranslator = _mockery.DynamicMock<ICharacterToFileNameTranslator>();
                _persistFile = _mockery.DynamicMock<IPersistFile>();
                _imageRepository = new ImageRepository(_characterToFileNameTranslator, _persistFile);
                SetupResult.For(_persistFile.From(null)).IgnoreArguments().Return(_persistFile);
                SetupResult.For(_persistFile.To(null)).IgnoreArguments().Return(_persistFile);
            }

            [Test]
            public void a_file_name_should_be_generated_for_it()
            {
                using (_mockery.Record())
                {
                    Expect.Call(_characterToFileNameTranslator.Using('a')).IgnoreArguments().Return(string.Empty).Repeat
                        .Once();
                }

                using (_mockery.Playback())
                {
                    _imageRepository.Save(string.Empty, 'a');
                }
            }

            [Test]
            public void the_file_should_be_saved()
            {
                using (_mockery.Record())
                {
                    _persistFile.Now();
                    LastCall.IgnoreArguments().Repeat.Once();
                }
                using (_mockery.Playback())
                {
                    _imageRepository.Save(string.Empty, 'a');
                }
            }
        }
    }
}